import { GIcon, GModalButton } from 'geminis-react';
import { CagegoryTree } from '@/pages/everydata/category/components/tree';
import { useRef } from 'react';
import request from 'umi-request';
import { message } from 'antd';

export const Move = (props: {
  id: string;
  disabled: boolean;
  onOk: () => void;
}) => {
  const tree = useRef<any>();

  const move = () => {
    return request
      .put(
        '/api/everydata/tables/' +
          props.id +
          '/move/' +
          tree.current.selection.selectedKeys[0],
      )
      .then(() => {
        message.success('成功');
        props.onOk?.();
      });
  };

  return (
    <GModalButton
      text="移动"
      button={{
        icon: <GIcon type="icon-move" />,
        disabled: props.disabled === true,
      }}
      onOk={move}
    >
      <CagegoryTree ref={tree} />
    </GModalButton>
  );
};
